﻿$(document).on("pageInit", "#cource-notice-list", function (e, id, page) {
    loadList();

    function loadList() {
        $(page).find("#list").empty();
        $.getJSON("/CourceNotice/GetCourceNoticeList", {}, function (response) {
            $.each(response, function (index, item) {
                var frame = $('<li class="cource-item" data-notice-id="' + item.Id + '">\
                    <div class="item-content">\
                        <div class="item-inner">\
                            <div class="item-title-row">\
                                <div class="item-title">' + item.Title + '</div>\
                                <div class="item-after">'+ item.CreateTime + '</div>\
                            </div>\
                            <div class="item-sub-title">课程：' + (item.CourceName || '') + '</div>\
                            <div class="item-text">内容：' + (item.Content || '') + '</div>\
                        </div>\
                    </div>\
                </li>');
                $(page).find("#list").append(frame);
            });
        });
    }

    $(page).on("click", ".cource-item", function (evt) {
        var buttons1 = [
        {
            text: '请选择',
            label: true
        },
        {
            text: '删除通知？',
            bold: true,
            onClick: function () {
                $.confirm("确定删除？", function () {
                    $.post("/CourceNotice/Delete?noticeId=" + evt.currentTarget.dataset.noticeId, function () {
                        loadList();
                    });
                }, function () {

                });
            }
        }];

        var buttons2 = [
          {
              text: '取消',
              bg: 'danger'
          }
        ];
        var groups = [buttons1, buttons2];
        $.actions(groups);
    });


    $(page).find("#menu-btn").on("click", function () {
        var buttons1 = [
        {
            text: '请选择',
            label: true
        },
        {
            text: '发布课程通知',
            bold: true,
            onClick: function () {
                $.router.load('/courcenotice/create', true);
            }
        }];

        var buttons2 = [
          {
              text: '取消',
              bg: 'danger'
          }
        ];
        var groups = [buttons1, buttons2];
        $.actions(groups);
    });
});